/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.bean;

import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import vehicle.bol.BrandBol;
import vehicle.bol.CarBOL;
import vehicle.bol.TypeBol;
import vehicle.entity.Brands;
import vehicle.entity.TypeVehicle;
import vehicle.entity.Vehicles;

/**
 *
 * @author MAKICHI
 */
@ManagedBean
@SessionScoped
public class AddVehicle {

    /** Creates a new instance of AddVehicle */
    private String brandName = "";
    private String typeVehicleName = "";
    private List<String> listBrand;
    private List<String> listTypeVehicle;
    private Vehicles vehicles;
    private TypeBol typeBol = new TypeBol();
    private List<TypeVehicle> lst;
    CarBOL carBOL = new CarBOL();
    BrandBol bolBrand = new BrandBol();

    public String getTypeVehicleName() {
        return typeVehicleName;
    }

    public void setTypeVehicleName(String typeVehicleName) {
        this.typeVehicleName = typeVehicleName;
    }

    public List<String> getListTypeVehicle() {
        return listTypeVehicle;
    }

    public String getBrandName() {

        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public List<String> getListBrand() {
        listBrand = new ArrayList<String>();
        List<Brands> li = bolBrand.getAllBrand();
        for (Brands it : li) {
            listBrand.add(it.getBrandName());
        }
        return listBrand;
    }

    public void setListBrand(List<String> listBrand) {
        this.listBrand = listBrand;
    }

    public void updateTypeVeicle() {
        listTypeVehicle = new ArrayList<String>();
        listTypeVehicle = bolBrand.typeVehicleByBrandName(brandName);
    }

    public AddVehicle() {
        vehicles = new Vehicles();
        this.lst = typeBol.getTypeVehicle();
    }

    public void displayLocation() {
        if (bolBrand == null || typeVehicleName == null) {
            FacesMessage msg = new FacesMessage("Selected", "Barnd:" + brandName + "typeVehicle" + typeVehicleName);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

    public String addVehicle() {
        return "AddNewCar.xhtml";
    }
    ///////////////////////////////////////////Add Brand
    private Brands brandadd=new Brands();

    public Brands getBrandadd() {
        return brandadd;
    }

    public void setBrandadd(Brands brandadd) {
        this.brandadd = brandadd;
    }
    
    public String addBrand()
    {
        
        return null;
    }

    public Vehicles getVehicles() {
        return vehicles;
    }

    public void setVehicles(Vehicles vehicles) {
        this.vehicles = vehicles;
    }

    public List<TypeVehicle> getLst() {
        return lst;
    }

    public void setLst(List<TypeVehicle> lst) {
        this.lst = lst;
    }

    public String addCar() {
        boolean flag = carBOL.addNewVehicle(vehicles);
        if (flag) {
            return "AddImge";
        } else {
            return "addVehicleFailed";
        }
    }
}
